﻿using System;
using System.Collections.Generic;
using System.Text;
using static M.Core.RmoteCall.RpcCall.RpcServiceInfo;

namespace M.Core.RmoteCall.RpcCall.Pool
{
    public class RpcPoolItem : IDisposable
    {
        public RpcPoolItem(RpcPool rpcPool, CallSocketObject callModel)
        {
            this.rpcPool = rpcPool;
            this._t = callModel;
            lastDate = DateTime.Now;
        }

        public bool IsUsing { get; set; } = false;
        public DateTime lastDate { get; set; }
        private RpcPool rpcPool;

        public DateTime LastUseTime;
        private CallSocketObject _t;


        public CallSocketObject GetInnerObject()
        {
            return _t;
        }

        public bool IsValidate()
        {
            if (_t.trans != null) return true;

            return false;
        }
        //释放资源
        public void Release()
        {
            if (_t.trans != null)
            {
                _t.trans.Dispose();
                _t.map = null;
            }
            _t = null;
        }
        //重新归池
        public void Dispose()
        {
            rpcPool.ReSet(this);
        }

    }
}
